<?php

namespace App\Api\V1\Controllers;

use App\Exceptions\ApiException;
use App\Jobs\Elesticsearch;
use App\Jobs\LogQueue;
use App\Jobs\PushQueue;
use App\Jobs\StatisticsQueue;
use App\Models\JpushMobile;
use App\Models\MediaLike;
use App\Models\MediaLikeLog;
use App\Models\MediaStar;
use App\Models\MobileMark;
use App\Models\Music;
use App\Models\MediaComment;
use App\Services\Behavior;
use App\Services\Filter;
use App\Services\MediaService;
use App\Services\Pusher;
use App\Services\Sts;
use Carbon\Carbon;
use App\Models\Media;
use App\Models\MusicType;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\DB;
use  App\Models\Report;
use Illuminate\Support\Facades\Cache;
use App\Services\Log;
use App\Models\ActivityConfig;
use App\Enum\ActivityEnum;

/**
 * 媒体中心
 * Class MediaController
 * @package App\Api\V1\Controllers
 */
class MediaController extends CommonController
{
    protected $media = null;

    public function __construct()
    {
        parent::__construct();
        // 获取用户基本信息
        $this->getUserInfo();
        $this->media = new Media();
    }

    /**
     * 媒体分类
     * @return array
     */
    public function mediaClass()
    {
        // 条件
        $select = array(
            'id','name'
        );
        $where = array(
            ['status','=',1]
        );
        $order = 'sorts desc,id desc';
        $return = D('media_class')
            ->select($select)
            ->where($where)
            ->orderByRaw($order)
            ->get();
        return json_success('ok', $return);
    }

    /**
     * 媒体位置  --作废
     * @return array
     */
    public function mediaPosition()
    {
        // 条件
        $select = array(
            'id','name'
        );
        $where = array(
            ['status','=',1]
        );
        $order = 'sorts desc,id desc';
        $return = D('media_position')
            ->select($select)
            ->where($where)
            ->orderByRaw($order)
            ->get();
        foreach ($return as $k => $v) {
            if ($v->name == '首页') {
                $return[$k]->name = '发布到首页';
            } else if ($v->name == '社区') {
                $return[$k]->name = '发布到社区';
            } else {
                $return[$k]->name = '全部';
            }
        }
        return json_success('ok', $return);
    }

    /**
     * 更新影片封面和时长
     * @return array
     */
    public function mediaUpdate()
    {
        $media_id = IT('media_id', true, '请选择影片', 10178); // 影片id
        $cover = IT('cover', true, '缺少影片封面图', 10179); // 影片封面
        $length = IT('length', true, '缺少影片时长', 10180); // 影片时长 单位：秒

        $media = Media::find($media_id);
        $uid = $this->uid;

        if (!$media || $media->uid !== $uid) {
            return json_error('参数错误', [], 10181);
        }

        $media->cover = $cover;
        $media->vedio_length = parseDuration($length);
        $media->save();

        Log::info(__FILE__, 'media_Update', ['cover' => $cover, 'length' => $length], '更新影片封面和时长, 数据为: ');

        return json_success('ok', [], 10000);
    }

    /**
     * 媒体上传
     * @return array
     */
    public function mediaUpload(Request $request)
    {
        //影片名称
        $title = IT('title',true,'请输入影片名称', 10182);
        // 概述
        $description = IT('description');
        //编剧
        $screenwriter = IT('screenwriter') ?: '';
        //主演
        $staring = IT('staring') ?: '';
        //演员
        $player = IT('player') ?: '';
        //导演
        $director = IT('director') ?: '';
        //是否私密 1:私密  0:公开  2:亲友圈
        $is_private = IT('private') ? ((int) IT('private')) : 0;
        // 位置信息
        $location = IT('location') ?: '';
        // 具体地址
        $address = IT('address') ?: '';
        // 是否原创
        $is_owner = IT('owner') ? 1 : 0;
        // 视频封面图
        $media = IT('media', true, '请上传封面图', 10183);
        // 影片时长 单位：秒
        $length = IT('length', true, '请上传影片时长', 10184);
        // 标签
        $tags = IT('tags', true, '请选择标签', 10185);

        $province = IT('province');
        $city = IT('city');

        $is_screen_recording = IT('is_screen_recording');
        $is_participate_activity = IT('is_participate_activity');

        $is_private = !in_array($is_private, [0, 1, 2]) ? 0 : $is_private;

        if (!preg_match('/\d+(\,\d)*/', $tags))
            return json_error('请选择标签', [], 10185);

        $tags = explode(',', $tags);
        $_tags = D('tags_name')->whereIn('id', $tags)->get();
        if (!$_tags)
            return json_error('标签选择有误', [], 10186);

        $tag_arr = [];
        foreach ($_tags as $t) {
            $tag_arr[] = $t->id;
        }

        foreach ($tags as $k => $t)
            if (!in_array($t, $tag_arr))
                unset($tags[$k]);

        if (empty($tags))
            return json_error('标签选择有误', [], 10186);

        $tags = implode(',', $tags);

        $uid = $this->uid;

        // 过滤敏感词
        $title = Filter::init($title);
        if (!empty($screenwriter)){
            $screenwriter = json_encode(explode(',', trim($screenwriter, ',')), JSON_UNESCAPED_UNICODE);
            if (!is_json($screenwriter))
                return json_error('编剧格式错误', [], 10187);
        }

        if (!empty($staring)){
            $staring = json_encode(explode(',', trim($staring, ',')), JSON_UNESCAPED_UNICODE);
            if (!is_json($staring))
                return json_error('主演格式错误', [], 10188);
        }
        if (!empty($director)) {
            $director = json_encode(explode(',', trim($director, ',')), JSON_UNESCAPED_UNICODE);
            if (!is_json($director)) {
                return json_error('导演格式错误', [], 10189);
            }
        }
        if (!empty($player)) {
            $player = json_encode(explode(',', trim($player, ',')), JSON_UNESCAPED_UNICODE);
            if (!is_json($player)) {
                return json_error('演员格式错误', [], 10190);
            }
        }

        if(($is_participate_activity == 1) && ($is_private != 0)) {
            return json_error('只有公开的视频才能参与活动', [], 10261);
        }

        // 检测
        if($is_participate_activity == 1) {
            $current_time = time();
            $activity_where = [['status', '=', ActivityEnum::ACTIVITY_STATUS_VALID], ['start_time', '<=', $current_time],['end_time', '>', $current_time], ['activity_type', '=', ActivityEnum::ACTIVITY_TYPE_LIKE]];
            $has_activity = ActivityConfig::where($activity_where)->first();
            if(!$has_activity) {
                $is_participate_activity = 0;
            }
        }

        DB::beginTransaction();
        // media表插入信息
        $insert = array(
            'uid'           => $uid,
            'title'         => $title,
            'description'   => $description,
            'cover'         => $media,
            'screenwriter'  => $screenwriter,
            'staring'       => $staring,
            'director'      => $director,
            'player'        => $player,
            'address'      => $address,
            'location'      => $location,
            'province'      => $province,
            'city'      => $city,
            'status'        => 2,
            'created_at'    => time2date(),
            'updated_at'    => time2date(),
            'date'          => date('Y-m-d'),
            'is_delete'     => 0,
            'video_length'  => parseDuration($length),
            'is_private'    => $is_private,
            'is_owner'      => $is_owner,
            'tags'          => $tags
        );

        if($is_screen_recording == 1) {
            $insert['is_screen_recording'] = $is_screen_recording;
        }
        if($is_participate_activity == 1) {
            $insert['is_participate_activity'] = $is_participate_activity;
        }

        $media_id = D('media')->insertGetId($insert);
        if (empty($media_id)) {
            DB::rollBack();
            return json_error('上传失败，请重试', [], 10191);
        }
        DB::commit();
        return json_success('上传成功', ['media_id' => $media_id], 10161);
    }
    /**
     * 获取视频和封面访问权限
     * @return array
     */
    public function previewMedia()
    {
        $media_id = IT('media_id', true, '请选择预览的视频', 10192);
        $media = Media::find($media_id);
        if (!$media || !$media->media || !$media->cover || $media->status != '1' || $media->is_delete == '1') {
            return json_error('视频不存在', [], 10193);
        }

        $media->media = getSignUrl($media->media);
        $media->cover = getSignUrl($media->cover);

        return json_success('ok', ['cover' => $media->cover, 'media' => $media->media, 'video_length' => $media->video_length], 10000);
    }

    /**
     * 解析媒体域名
     * @param string $mediaUrl
     * @return array
     */
    private function parseUrl($mediaUrl = '')
    {
        $data = parse_url($mediaUrl);

        return ['bucketName' => substr($data['host'], 0, strpos($data['host'], '.')), 'ossKey' => substr($data['path'], 1)];
    }

    /**
     * 删除文章
     * @return array
     */
    public function delMedia()
    {
        // 获取数据
        $media_id = IT('media_id',true);
        $uid = $this->uid;

        // 防止用户频繁操作删除文章
        if (cache('media_del_media' . $uid)) {
            EE('请勿频繁操作',0, 10113);
        }

        cache(['media_del_media' . $uid => $uid], Carbon::now()->addSecond(1));
        DB::beginTransaction();
        // 删除文章
        $res = D('media')->where([['id','=',$media_id],['uid','=',$uid],['is_delete','=',0]])->update(['is_delete'=>1]);
        if (!$res) {
            DB::rollBack();
            return json_error('操作失败！请查看是否是自己原创视频', [], 10194);
        }
        // 更新视频的动态无效
        $update = MediaService::changeDynamic(['media_id'=>$media_id], ['status'=>'0']);

        // 删除评论
        D('media_comment')->where([['media_id','=',$media_id],['is_delete','=',0]])->update(['is_delete'=>1, 'status' => 0]);

        // 删除转发的视频
        $res = D('media')->where([['parent_id','=',$media_id],['is_forward','=',1],['is_delete','=',0]])->update(['is_delete'=>1]);
        DB::commit();

        $temp_arr = [];
        // 队列   --添加搜索索引
        $temp_arr['mid'] = $media_id;
        dispatch((new Elesticsearch(['type'=>'2', 'action'=>'del', 'data'=>$temp_arr]))->onQueue('eleasticsearch'));
        return json_success('成功删除', [], 10115);
    }

    /**
     * 修改发布过的文章
     * @return array
     */
    public function modifyMedia()
    {
        // 获取数据
        $media_id = IT('media_id',true);
        $type = IT('type');
        $class_id = IT('class_id');
        $position_id = IT('position_id');
        $title = IT('title');
        $content = IT('content');
        // 媒体路径（JSON格式）
        $media_json = IT('media') ? IT('media') : '';
        // 是否首页推广
        $index_extend = IT('extend') ? IT('extend') : 0;
        $update_array = [
          'type' => $type,
          'class_id' => $class_id,
          'position_id' => $position_id,
          'title' => $title,
          'content' => $content,
          'media' => $media_json,
          'extend' => $index_extend
        ];
        foreach ($update_array as $key => $value){
            if(empty($value)){
                unset($update_array[$key]);
            }
        }
        $update_array['updated_at'] = time2date();
        $uid = $this->uid;

        // 防止用户频繁操作修改文章
        if (cache('media_modify_media' . $uid)) {
                EE('请勿频繁操作',0, 10113);
        }
        cache(['media_modify_media' . $uid => $uid], Carbon::now()->addSecond(1));
        DB::beginTransaction();
        // 删除文章
        $res = D('media')
            ->where([['id','=',$media_id],['uid','=',$uid],['status','=',1],['is_delete','=',0]])
            ->update($update_array);
        if (empty($res)) {
            DB::rollBack();
            return json_error('操作失败',[], 10001);
        }
        DB::commit();
        return json_success('修改成功', [], 10119);
    }

    /**
     * 删除评论
     * @return array
     */
    public function delComment()
    {
        // 获取数据
        $comment_id = IT('comment_id',true, '未知删除评论数据', 10195);
        $uid = $this->uid;

        // 防止用户频繁操作删除评论
        if (cache('media_del_Comment' . $uid))
            EE('请勿频繁操作', 0, 10113);
        cache(['media_del_Comment' . $uid => $uid], Carbon::now()->addSecond(1));

        $delResult = MediaService::delComment($uid, $comment_id);
        if ($delResult ==false)
            return json_error('操作失败', [], 10001);
        else
            return json_success('删除成功', [], 10196);
    }

    /**
     * 添加影片收藏
     * @return array
     */
    public function collectMedia(Request $request)
    {
        $media_id = IT('media_id',true);
        $uid = $this->uid;
        $res_user = D("media")
            ->where(['id' => $media_id])
            ->first();
        if(empty($res_user)){
            EE("该视频不存在!");
        }
        $res_media = D("media_star")
            ->where(['uid' => $uid, 'media_id' => $media_id])
            ->first();
        if(!$res_media){
            $data = [
                'uid' => $uid ,
                'media_id' =>$media_id,
                'status' => 1,
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ];
            $id = DB::table('media_star')->insertGetId($data);
            $media_Star = D('media')->where('id',$media_id)->increment('star');
            if($media_Star){
                MediaStar::set_media_star($uid, $media_id, 'add');
                return json_success('收藏成功',$data, 10197);
            }else{
                 return json_error('收藏失败',$data, 10198);
            }
        }else{
            return json_error('该影片已收藏', [], 10199);
        }

        return json_error('false', [], 10001);
    }
    //取消影片收藏
    public function delCollectMedia(Request $request)
    {
        Log::info(__FILE__, 'delCollectMedia',  IT('media_id') );
        $media_id = IT('media_id',true);
        $uid = $this->uid;
        $res_user = D("media")
            ->where(['id' => $media_id])
            ->first();
        if(empty($res_user)){
            EE("该视频不存在!", 0, 10200);
        }
        $res_media = D("media_star")
            ->where(['uid' => $uid, 'media_id' => $media_id])
            ->first();
        if($res_media){
            $data = [
                'uid' => $uid ,
                'media_id' =>$media_id,
                'status' => 1,
            ];
            $id = DB::table('media_star')->where($data)->delete();
            $media_Star = D("media")->where('id', $media_id)->decrement('star');
            if($media_Star){
                MediaStar::set_media_star($uid, $media_id, 'del');
                return json_success('取消成功',[], 10201);
            }else{
                return json_error('取消失败',[], 10202);
            }
        }else{
            return json_error('未收藏该影片!', [], 10203);
        }

        return json_error('false', [], 10001);
    }

    //信息举报
    public function report (Request $request){
        $media_id = $request->input('media_id');
        $type = $request->input('id');
        $content = $request->input('content');
        $insert_date = [
            'media_id' => intval($media_id),
            'report_type' => intval($type),
            'content' => $content,
            'report_time' => time2date(),
            'uid' => $this->user_info->id
        ];
        $update = Report::insert($insert_date);
        if($update){
            $update && false !== DB::table('media')->where('id', $media_id)->increment('reports_number');
            return json_success('举报成功', [], 10204);
        }else{
            return json_error('举报失败', [], 10205);
        }
    }
    /**
     * @return array
     * 举报的类型
     */
    public function ReportType(){
        $video_type = D("report_type")->where('type','=',1)->get(['id','name', 'type_code']);
        $people_type = D("report_type")->where('type','=',2)->get(['id','name', 'type_code']);
        return json_success('ok',[ 'video_type'=>$video_type, 'people_type' =>$people_type]);
    }
    //视频点赞
    public function praise(){

        $media_id = IT('media_id',true);
        $mobile_unique_code = IT('mobile_unique_code',true, '设备唯一标识必填', 10073);

        $uid = $this->uid;
        $media = D("media")
            ->where(['id' => $media_id])
            ->first();
        if(empty($media)){
            EE("该视频不存在!", 0, 10200);
        }

        DB::beginTransaction();
        $res = false !== D('media')->where('id', $media_id)->increment('like');
        $res = $res && false !== D('users')->where('id', $media->uid)->increment('praise');
        $media_like = DB::table('media_like')->where([ ['media_id', $media_id], ['uid', $uid] ])->first();
        if ($media_like) {
            if ($media_like->is_delete == '0') {
                DB::rollback();
                return json_error('已点赞该视频', [], 10206);
            }
            $res = $res && false !== DB::table('media_like')->where('id', $media_like->id)->update(['is_delete' => 0]);
        } else {
            $res = $res && DB::table('media_like')->insert(['media_id' => $media_id, 'uid' => $uid, 'created_at' => time2date()]);
        }

        if($res){
            /*DB::commit();
            Behavior::write($uid, $media_id);*/

            // 获取设备信息
            $mobile_unique_code_data = MobileMark::getRowsArray([['mobile_unique_code', '=', $mobile_unique_code]]);

            $mobileMarkId = empty($mobile_unique_code_data) ? '0' : $mobile_unique_code_data['id'];
            $province = empty($mobile_unique_code_data['province']) ? '0' : $mobile_unique_code_data['province'];
            $city = empty($mobile_unique_code_data['city']) ? '0' : $mobile_unique_code_data['city'];

            // 添加点赞日志
            $log_model = new MediaLikeLog();
            $log_model->type = 1;
            $log_model->media_id = $media_id;
            $log_model->media_uid = $media->uid;
            $log_model->operation_uid = $uid;
            $log_model->create_time = time();

            if($log_model->save()){

                // 队列  --写入行为记录
                $data['uid'] = $uid;
                $data['media_id'] = $media_id;
                $data['action'] = 0;
                $data['duration'] = 0;
                $data['mobileMarkId'] = $mobileMarkId;
                $data['province'] = $province;
                $data['city'] = $city;
                dispatch((new LogQueue(['type'=>'recommend', 'data'=>$data]))->onQueue('log_queue'));

                if($media->is_participate_activity == 1){
                    // 点赞统计队列  type:1 点赞
                    $user_statisctics = ['action'=>'media_like', 'data'=>['type'=>'1', 'media_like_log_id'=>$log_model->id]];
                    dispatch((new StatisticsQueue($user_statisctics))->onQueue('statistics'));
                }
                DB::commit();
                MediaLike::set_media_like($uid, $media_id, 'add');
                return json_success('点赞成功', [], 10207);
            }
        }

        DB::rollback();
        return json_error('点赞失败', [], 10208);
    }

    //视频取消点赞
    public function CancelPraise(){

        $media_id = IT('media_id',true);
        $uid = $this->uid;
        $media = D("media")
            ->where(['id' => $media_id])
            ->first();
        if(empty($media)){
            EE("该视频不存在!", 0, 10200);
        }

        $media_like = DB::table('media_like')->where([ ['media_id', $media_id], ['uid', $uid] ])->first();
        if (!$media_like || $media_like->is_delete == '1') {
            return json_error('未点赞该视频', [], 10209);
        }

        DB::beginTransaction();
        $res = false !== D('media')->where('id', $media_id)->decrement('like');
        $res = $res && false !== D('users')->where('id', $media->uid)->decrement('praise');
        $res = $res && false !== D('media_like')->where('id', $media_like->id)->update(['is_delete' => 1]);
        if($res){
            // 添加点赞日志
            $log_model = new MediaLikeLog();
            $log_model->type = 2;
            $log_model->media_id = $media_id;
            $log_model->media_uid = $media->uid;
            $log_model->operation_uid = $uid;
            $log_model->create_time = time();
            if($log_model->save()){

                // 参与活动
                if($media->is_participate_activity == 1){
                    // 点赞统计队列  type:1 点赞
                    $user_statisctics = ['action'=>'media_like', 'data'=>['type'=>'-1', 'media_like_log_id'=>$log_model->id]];
                    dispatch((new StatisticsQueue($user_statisctics))->onQueue('statistics'));
                }
                DB::commit();
                MediaLike::set_media_like($uid, $media_id, 'del');
                return json_success('取消点赞成功', [], 10210);
            }
        }

        DB::rollback();
        return json_error('取消失败', [], 10211);
    }
    /**
     * 音乐列表
     * @return array
     */
    public function musicList()
    {
        $type = IT('type', true, '请选择音乐类型',10096);
        $music_type = MusicType::where('id',$type)->first();
        if (!$music_type ) {
            return json_error('没有该类型',[], 10097);
        }
        $where=[ ['category',$type],['is_delete',0],['status',0]];

        $list = Music::where($where)->orderBy('sort','ASC')->orderBy('number','desc')->get(['id', 'music_name', 'music_link', 'time_length']);

        $list = !$list ? [] : $list;
        foreach ($list as &$l) {
            $l->music_link = getSignUrl($l->music_link);
        }
        unset($l);
        return json_success('ok', $list,10000);
    }

    /**
     * 音乐分类
     * @return array
     *
     */
    public function MusicType(){
        $type_data = MusicType::where('status','=',0)->orderBy('sort','desc')->get(['id','name', 'type_code']);
        return json_success('ok',$type_data,10000);
    }

    /**
     *音乐应用统计
     *
     */
    public function MusicCount(){
        $id= IT('id',true,'请上传音乐ID',10098);
        $music_data = Music::find($id);
        if(!$music_data){
            EE('音乐不存在', 0, 10212);
        }
        DB::beginTransaction();
        $data = D('system_music')->where('id','=',$id)->increment('number');
        if($data){
            DB::commit();
            return json_success('ok',[],10000);
        }else{
            DB::rollback();
            return json_error('失败',[], 10000);
        }
    }

    /*
     * 视频评论列表
     * */
    public function index_mediaCommentsList(Request $request){

        IT('media_id', true, '未知视频评论',10099);

        $action_type =  $request->input('action_type', 2);

        $media_id =  $request->input('media_id');
        $start_comment_id =  $request->input('start_comment_id', 0);
        $end_comment_id =  $request->input('end_comment_id');
        $page =  $request->input('page');
        $pagesize =  $request->input('pagesize');

        // 获取视频列表
        $data = MediaService::getMediaCommentList($request);
        return json_success('ok',['media_id'=>$media_id, 'next_page'=>$data['next_page'], 'comments_total'=>$data['comments_total'], 'list'=>empty($data['list']) ? null : $data['list']], 10000);
    }

    /*
     * 视频评论/回复
     *
     * */
    public function index_addMediaComments(Request $request)
    {
        $uid = $this->uid;
        $media_id = IT('media_id', true, '未知视频资讯',10100);
        $content = IT('content', true, '评论或回复内容必填', 10101);
        $type = IT('type', true, '评论类型必填', 10102);
        $media_comments_id = IT('media_comments_id', 0);
        $type = IT('type');

        // 添加视频
        $action = 'add_media_comments';
        // 返回视频内容，评论内容
        $result = MediaService::$action($request, $uid);

        if(empty($result) || $result['status'] == 'error')
            return json_error( isset($result['message']) ? $result['message'] : '评论异常', 10000);

        // 推送--队列 --对视频发布者/被回复用户 推送
        $temp_uid = ($type == 1) ? $result['data']['media_info']->uid : $result['data']['media_comments']['reply_uid'];

        $_user = D('users')->find($temp_uid);

        if ($_user && $_user->registration_id){

            $getPushChannel = JpushMobile::getRowsArray([['registration_id', '=', $_user->registration_id]]);
            // 消息推送
            if(!empty($getPushChannel) && !empty($getPushChannel['push_channel_id'])){
                /*Pusher::message($_user->registration_id, '其他用户评论了您发布的视频', ['type' => 2]);*/

                $notifyContent = trans('notice.10213');//'其他用户评论了您发布的视频';
                if($type == 2)
                    $notifyContent = trans('notice.10214');//'其他用户回复了您的评论';

                ////////////////////////////////////////////////////////////////////////////////////////////////
                // 标题  --app 通过notify id 0处理业务 --透传
                $data = [];
                $push_channel_key = 'jpush';
                if($getPushChannel['push_channel_id'] == 2){
                    $push_channel_key = 'hpush';
                }else if($getPushChannel['push_channel_id'] == 3){
                    $push_channel_key = 'xmpush';
                }

                $data['channel_id'] = $getPushChannel['push_channel_id'];
                $data['title'] = trans('notice.10215');//'评论/回复'; // 登录标题
                $data['content'] = $notifyContent;// 内容
                $data['description'] = $notifyContent; // 描述
                $data['msg_type'] = config('push')[$push_channel_key]['type']['ospf'];  // 消息类型：1通知 0透传
                $data['notify_id'] = 2;     // 通知id   --app 处理业务标识
                $data['notify_foreground'] = 0; // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
                $data['mobile_list'] = $getPushChannel['registration_id'];
                $data['mobile_unique_code'] = IT('mobile_unique_code');
                dispatch((new PushQueue(['type'=>'singlePush', 'data'=>$data]))->onQueue('push'));
                ////////////////////////////////////////////////////////////////////////////////////////////////
            }
        }

        $data = [
            'id'=> $result['data']['media_comments']->id,
            'uid' =>  $uid,
            'username' => $this->user_info->name,
            'avatar' => getSignUrl($this->user_info->avatar),
            'content' =>$result['data']['media_comments']->content,
            'replay_count' =>MediaComment::where('parent_id','=',$result['data']['media_info']->id)->count(),
            'created_at' =>time2date(),
            'reply_uid' =>empty($result['data']['media_comments']->reply_uid) ? 0 : $result['data']['media_comments']->reply_uid,
            'reply_name' =>empty($result['data']['media_comments']->reply_name) ? "" : $result['data']['media_comments']->reply_name,
        ];
        return json_success('ok',$data,10000);
    }

    /*
     * 发布最新视频导演/演员
     * */
    public function director(Request $request)
    {
        $uid = $this->uid;

        // 获取视频详情
        $data = MediaService::getMediaDirector($uid);

        return json_success('ok', $data, 10000);
    }

    /**
     * @desc 转发视频
     */
    public function ForwardingMedia()
    {
        $params['uid'] = $this->uid;
        $params['media_id'] = IT('media_id', true, '未知视频资讯',10100);
        $params['content'] = IT('content');
        $forwarding_rs = MediaService::forwardingMedia($params);

        if(!$forwarding_rs) {
            return json_success('转发失败',[],10000);
        }

        return json_success('转发成功!',[],10000);
    }
}